package huaweiod.first;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 华为OD机试真题 Java 实现【通信误码】【2022.11 Q4 新题】
 * 5
 * 1 2 2 4 1
 * 2
 * <p>
 * 7
 * 1 2 2 4 2 1 1
 * 4
 */
public class A_2023_58_CommunicationError {

    public static class ArrCount {
        int value;
        int indexPre;
        int indexLast;
        int count;

        public ArrCount(int value, int indexPre, int indexLast, int count) {
            this.value = value;
            this.indexPre = indexPre;
            this.indexLast = indexLast;
            this.count = count;
        }

        public int getLen() {
            return this.indexLast - this.indexPre + 1;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        Map<Integer, ArrCount> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            if (map.containsKey(arr[i])) {
                ArrCount arrCount = map.get(arr[i]);
                arrCount.indexLast = i;
                arrCount.count++;
            } else {
                map.put(arr[i], new ArrCount(arr[i], i, i, 1));
            }
        }
        int len = n;
        int count = 1;
        for (Map.Entry<Integer, ArrCount> entry : map.entrySet()) {
            ArrCount ac = entry.getValue();
            if (ac.count >= count && ac.getLen() < len) {
                count = ac.count;
                len = ac.getLen();
            }
        }
        System.out.println(len);
    }
}
